<?php

namespace app\admin\controller;

use app\common\model\Admin;
use app\http\middleware\checkAdminToken;
use think\Controller;
use think\facade\Request;

class Login extends Controller
{
    //登录
    public function login( )
    {
        if (Request::param('password')) {
            return $this->passwordLogin(Request::param('account'), Request::param('password'));
        }

        if (Request::param('verCode')) {
            $this->passwordLogin(Request::param('mobile'), Request::param('password'));
        }

    }

    //密码登录
    private function passwordLogin($account, $password)
    {
        $user =Admin::where('account', $account)->where('password', md5($password))->find();
        if($user){
            $data = [
                "token" => checkAdminToken::issueToken($user),
                'user'=>$user
            ];
            $this->result($data,200,'登陆成功');
//            return toResful(200, $data, '登陆成功');
        }else{
            return toResful(400, $user, '账号或密码错误');
        }
    }

}
